import argparse, json, pandas as pd
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/..")
from stable_baselines3 import PPO
from star_env import StarEnv

if __name__ == "__main__":
    ap = argparse.ArgumentParser()
    ap.add_argument("--catalog", required=True)
    ap.add_argument("--model", required=True)
    ap.add_argument("--out", required=True)
    args = ap.parse_args()

    df = pd.read_csv(args.catalog)
    env = StarEnv(df)
    model = PPO.load(args.model)

    obs, _ = env.reset()
    infos = []
    for _ in range(200):
        action, _ = model.predict(obs, deterministic=True)
        obs, r, done, trunc, info = env.step(action)
        infos.append(info)

    with open(args.out, "w") as f:
        json.dump(infos[-1], f, indent=2)  # 保存最后状态的指标
    print(infos[-1])
